{include file="../common/header"}
<!--页面主要内容-->
<main class="lyear-layout-content">

  <div class="container-fluid">

    <div class="row">
      <div class="col-lg-12">
        <div class="card">
          <div class="card-body">

            <div class="form-group">
              <label for="old-password">旧密码</label>
              <input type="password" class="form-control" name="oldpwd" id="old-password" placeholder="输入账号的原登录密码">
            </div>
            <div class="form-group">
              <label for="new-password">新密码</label>
              <input type="password" class="form-control" name="newpwd" id="new-password" placeholder="输入新的密码">
            </div>
            <div class="form-group">
              <label for="confirm-password">确认新密码</label>
              <input type="password" class="form-control" name="confirmpwd" id="confirm-password" placeholder="请在输入一遍新的密码">
            </div>
            <button type="button" id="updatepassword" class="btn btn-primary">修改密码</button>

          </div>
        </div>
      </div>

    </div>

  </div>

</main>
<!--End 页面主要内容-->
</div>
</div>
{include file="../common/footer"}
<script>
  $("#updatepassword").click(function () {
    var l = $('body').lyearloading({
      opacity: 0.2,
      spinnerSize: 'lg'
    });
    var oldpwd = $.trim($("#old-password").val());
    var newpwd = $.trim($("#new-password").val());
    var confirmpwd = $.trim($("#confirm-password").val());
    if (oldpwd == "" || newpwd == "" || confirmpwd == ""){
      $.alert({
        title: '错误提示',
        icon: 'mdi mdi-alert',
        type: 'red',
        content: '请输入完整',
      });
      return false;
    }
    if (newpwd != confirmpwd){
      $.alert({
        title: '错误提示',
        icon: 'mdi mdi-alert',
        type: 'red',
        content: '两次密码不一致'
      });
      return false;
    }
    $.ajax({
      type: 'post',
      url: "{:url('/admin/admin/changepwd')}",
      data: {
        oldpwd:oldpwd,
        newpwd: newpwd,
      },
      dataType: 'json',
      success: function (data) {
        l.destroy();
        if (data.code == 200){
          location.reload();
        }else{
          $.alert({
            title: '错误提示',
            icon: 'mdi mdi-alert',
            type: 'red',
            content: data.msg
          });
        }
      }
    })
  })
</script>
</body>
</html>